// 缓存 页面筛选条件 ===============================================================
const paramsStorageKeyText = 'paramsStorage';
export const $setParamsStorage = (params: ObjValueAny, key: string = ''): void => {
    const sessKey = `${paramsStorageKeyText}${key}`
    if (params) sessionStorage.setItem(sessKey, JSON.stringify(params));
};

// 获取并删除 页面筛选条件
export const $getParamsStorage = (key: string = ''): ObjValueAny => {
    let params: ObjValueAny = {};
    const sessKey = `${paramsStorageKeyText}${key}`
    if (sessionStorage.getItem(sessKey)) {
        params = JSON.parse(sessionStorage.getItem(sessKey) as string);
    }
    $removeParamsStorage(key);
    return params;
};

// 删除 页面筛选条件
export const $removeParamsStorage = (key: string = ''): void => {
    const sessKey = `${paramsStorageKeyText}${key}`
    sessionStorage.removeItem(sessKey);
};

// 清除 页面筛选条件
export const $resetParamsStorage = (): void => {
    for (const key in sessionStorage) {
        if (key.startsWith(paramsStorageKeyText)) {
            delete sessionStorage[key]
        }
    }
};


import { getFilterTimeParams } from "@/components/globalUtils/GFilterTime";
import { getSearchParams } from "@/components/globalUtils/GSearch";
// 获取列表 筛选参数
export const $getMountedParams = (type: string, params: ObjValueAny = {}) => {
    const _dateParams = getFilterTimeParams(type);
    const _searchParams = getSearchParams(type);
    const resp: ObjValueAny = $getParamsStorage();
    if (resp.page) {
        for (let key in resp) {
            if (params.hasOwnProperty(key) || _dateParams.hasOwnProperty(key) || _searchParams.hasOwnProperty(key)) {
                params[key] = resp[key];
            }
        }
    }
    return resp;
}

export const $getMountedMdSearch = (type: string, params: ObjValueAny = {}, searchParams: ObjValueAny = {}) => {
    const _dateParams = getFilterTimeParams(type);
    const _searchParams = getSearchParams(type);
    const resp: ObjValueAny = $getParamsStorage();
    if (resp.page) {
        for (let key in resp) {
            if (params.hasOwnProperty(key)) {
                params[key] = resp[key];
            }
            if (_dateParams.hasOwnProperty(key) || _searchParams.hasOwnProperty(key)) {
                searchParams[key] = resp[key];
            }
        }
    }
    return resp;
}